﻿@model S4sme.Tasks.Blog.ViewModels.EditPostViewModel

@{
    ViewBag.Title = "Edit";
    Layout = "../Shared/_AdminLayout.cshtml";
}

@section Stylesheets{
<link href="@Url.Content("~/Content/css/cleditor/jquery.cleditor.css")" rel="stylesheet" type="text/css" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.js" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/cleditor/jquery.cleditor.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Post_Content").cleditor({ width: "1000px", height: "600px" });
    });
</script>
}

<h2>Post Form</h2>

@using (Html.BeginForm("EditPost", "Admin")) {
    @Html.ValidationSummary("Please note the following:")
    @Html.AntiForgeryToken()

    <fieldset>
        <legend>Post</legend>

        @Html.HiddenFor(m => m.Post.Id)
        @Html.EditorFor(m => m.Post.Title)
        @Html.EditorFor(m => m.Post.Description)
        @Html.TextAreaFor(m => m.Post.Content)

        <div class="editor-label">
            @Html.LabelFor(m => m.Post.Categories)
        </div>
        <div class="editor-field">
            @foreach (var category in Model.AvailableCategories) {
                <input id="post_Categories_@category.Id" type="checkbox" name="post.Categories" value="@category.Id" 
                    @(Model.Post.Categories.Contains(category) ? "checked=\"checked\"" : "") />
                <label for="post_Categories_@category.Id">@category.Name</label><br />
            }

            @Html.ValidationMessageFor(m => m.AvailableCategories)
        </div>

        <div class="editor-label">
            @Html.LabelFor(m => m.Post.Tags)
        </div>
        <div class="editor-field">
            @foreach (var tag in Model.AvailableTags) {
                <input id="post_Tags_@tag.Id" type="checkbox" name="post.Tags" value="@tag.Id" 
                    @(Model.Post.Tags.Contains(tag) ? "checked=\"checked\"" : "") />
                <label for="post_Tags_@tag.Id">@tag.Name</label><br />
            }

            @Html.ValidationMessageFor(m => m.AvailableTags)
        </div>

        <p>
            <input type="submit" value="Save" /> 
            @Html.ActionLink("Cancel", "Posts")
        </p>
    </fieldset>
}
